<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
<title>{echo admin_title()}</title>
<!--header-->
{template _:header}
</head>
<body>
<div class="layui-layout layui-layout-admin">
<!--top-->
{template _main_top}
<!--nav-->
{template _main_nav}
	<div class="position"><h1>收款码管理</h1></div>
	<div class="layui-body admin-body">
		<div class="admin-content">
			<div class="searcher">
				<div class="right"><button type="button" class="layui-btn layui-add">生成收款码</button></div>
				<form name="sch_form" id="sch_form" method="get" action="{echo \befen\get_url()}">
					<div class="layui-input-inline">
						<input type="text" name="store_name" id="store_name" class="layui-input" value="{echo input('param.store_name')}" placeholder="门店名称">
					</div>
					<div class="layui-input-inline layui-left-margin"><button type="submit" id="search" class="layui-btn">查询</button></div>
				</form>
				<div class="clear"></div>
			</div>
			<form name="theform" id="theform" method="post" action="{echo \befen\get_url()}">
			<table class="layui-table">
				<thead>
					<tr>
						<th>收款码ID</th>
						<th>所属门店</th>
						<th>所属员工</th>
						<th>绑定设备</th>
						<th>状态</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody>
					<!--{loop $list $key $val}-->
					<tr id="">
						<td>P{$val[id]}</td>
						<td><!--{if !$val[store_id]}--><a op="bind_store" lay-id="{$val[id]}" class="layui-btn layui-badge layui-bg-gray">未绑定</a><!--{else}--><a op="bind_store" lay-id="{$val[id]}" class="layui-btn layui-badge layui-bg-blue">{$val[store_name]}</a><!--{/if}--></td>
						<td><!--{if !$val[person_id]}--><a op="bind_person" lay-id="{$val[id]}" class="layui-btn layui-badge layui-bg-gray">未绑定</a><!--{else}--><a op="bind_person" lay-id="{$val[id]}" class="layui-btn layui-badge layui-bg-blue">{$val[per_name]}</a><!--{/if}--></td>
						<td><!--{if !$val[device_id]}--><a op="bind_device" lay-id="{$val[id]}" class="layui-btn layui-badge layui-bg-gray">未绑定</a><!--{else}--><a op="bind_device" lay-id="{$val[id]}" class="layui-btn layui-badge layui-bg-blue">{$val[SN]}</a><!--{/if}--></td>
						<td><span class="layui-badge layui-bg-status-1">正常</span></td>
						<td class="op">
							<a op="qrcode" id="P{$val[id]}" lay-url="{echo url('/p/' . $val['id'], null, null, true)}" class="layui-btn layui-btn-xs layui-btn-normal">查看二维码</a>
						</td>
					</tr>
					<!--{/loop}-->
				</tbody>
			</table>
			</form>
			<div class="listpages">{$pagenav}</div>
		</div>
	</div>
</div>
<!--footer-->
{template _:footer}
<script type="text/javascript">
$('#time_create').attr('autocomplete', 'off');
layui.use('laydate', function(){
	var laydate = layui.laydate;
	laydate.render({ 
		elem: '#time_create',
		range: '~'
	});
});
$('#sch_form input[name=store_name]').autoComplete({
	url: "{echo url('store/index')}",
	field: "",
	value: "{echo input('param.store_name')}",
	name_hidden: "store_id",
	value_hidden: "{echo input('param.store_id')}",
});
$(".layui-add").click(function(){	
	init_Layer(function(){
		layer.prompt({
			title: "请输入收款码数量",
			value: "",
		}, function(value, index){
			$.ajax({
				type: "POST",
				dataType: "json",
				cache: false,
				timeout: 30000,
				url: "{echo url('qrcode/create')}",
				data: {
					ajax: "json",
					count: value,
				},
				success: function(data){
					if(data.status == 1) {
						showInfo(data.message, function(){
							reload();
						});
					} else {
						showAlert(data.message);
					}
				},
				error: function(xhr, status){
					console.log(xhr);
				},
				complete: function(){
					hideLoader();
				},
				beforeSend: function(){
					showLoader();
				}
			});
		});
	});
});
$("a[op=detail]").click(function(){
	//showWindow('', $(this).attr('lay-url'), '600px');
});
$("a[op=qrcode]").click(function(){
	var qr_id = $(this).attr('id');
	var qr_url = $(this).attr('lay-url');
	init_Layer(function(){
		layer.open({
			title: '收款码 - ' + qr_id,
			shade: 0.5,
			isOutAnim: true,
			content: '<div style="text-align:center"><div id="show_qrcode" style="width:250px;height:250px;margin:0 auto"></div><br /><h3>' + qr_id + '</h3></div>',
			btn: false
		});
		var qrcode = new QRCode(document.getElementById("show_qrcode"), {
			width: 250,
			height: 250
		});
		qrcode.makeCode(qr_url);
	});
});
$("a[op=bind_store]").click(function(){
	var id = $(this).attr('lay-id');
	init_Layer(function(){
		layer.prompt({
			title: "请输入门店ID",
			value: "",
		}, function(value, index){
			$.ajax({
				type: "POST",
				dataType: "json",
				cache: false,
				timeout: 30000,
				url: "{echo url('qrcode/bind_store')}",
				data: {
					ajax: "json",
					id: id,
					store_id: value,
				},
				success: function(data){
					if(data.status == 1) {
						showInfo(data.message, function(){
							reload();
						});
					} else {
						showAlert(data.message);
					}
				},
				error: function(xhr, status){
					console.log(xhr);
				},
				complete: function(){
					hideLoader();
				},
				beforeSend: function(){
					showLoader();
				}
			});
		});
	});
});
$("a[op=bind_person]").click(function(){
	var id = $(this).attr('lay-id');
	init_Layer(function(){
		layer.prompt({
			title: "请输入员工ID",
			value: "",
		}, function(value, index){
			$.ajax({
				type: "POST",
				dataType: "json",
				cache: false,
				timeout: 30000,
				url: "{echo url('qrcode/bind_person')}",
				data: {
					ajax: "json",
					id: id,
					person_id: value,
				},
				success: function(data){
					if(data.status == 1) {
						showInfo(data.message, function(){
							reload();
						});
					} else {
						showAlert(data.message);
					}
				},
				error: function(xhr, status){
					console.log(xhr);
				},
				complete: function(){
					hideLoader();
				},
				beforeSend: function(){
					showLoader();
				}
			});
		});
	});
});
$("a[op=bind_device]").click(function(){
	var id = $(this).attr('lay-id');
	init_Layer(function(){
		layer.prompt({
			title: "请输入设备SN",
			value: "",
		}, function(value, index){
			$.ajax({
				type: "POST",
				dataType: "json",
				cache: false,
				timeout: 30000,
				url: "{echo url('qrcode/bind_device')}",
				data: {
					ajax: "json",
					id: id,
					SN: value,
				},
				success: function(data){
					if(data.status == 1) {
						showInfo(data.message, function(){
							reload();
						});
					} else {
						showAlert(data.message);
					}
				},
				error: function(xhr, status){
					console.log(xhr);
				},
				complete: function(){
					hideLoader();
				},
				beforeSend: function(){
					showLoader();
				}
			});
		});
	});
});
</script>
</body>
</html>